package siafi.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import siafi.bean.PersonaCentro;
import siafi.db.TerceroDAO;
import siafi.util.Constantes;

/**
 * Servlet implementation class CentroCosto
 */
public class CentroCosto extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CentroCosto() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String concepto = request.getParameter("centroCosto");
		request.getSession().setAttribute("Concepto", TerceroDAO.findConcepto(concepto));
		request.getSession().setAttribute("servicios", null);
		request.getSession().removeAttribute("servicios");
		PrintWriter out = response.getWriter();
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">");
		out.println("<html>");
		out.println(" <head>");
		out.println(" <link href=\"./css/coolblue.css\" rel=\"stylesheet\" type=\"text/css\"/>");
		out.println(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">");
		out.println("  <title>Recibos</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("   <div align=\"center\" id=\"header\">");
		out.println(" <img src=\"./images/upn.jpg\"/>");
		out.println(" </div>");
		if( request.getSession().getAttribute("tercero")!=null){
		// si no se encontro a la persona
			out.println(" <div align=\"center\" id=\"content\">");
			out.println(" <form action=\"/recibosSIAFI/CantidadServicio\" method=\"post\">");
			out.println("     <table>");
			out.println(" <tr>");
			out.println(" <td colspan=\"2\"><h3>Recibo de Servicio</h1></td>");
			out.println("</tr>");
			out.println(" <tr>");
			out.println(" <td colspan=\"2\" align=\"left\"><h4 align=\"left\">"+((PersonaCentro)request.getSession().getAttribute("tercero")).getNombre()+"</h3></td>");
			out.println("</tr>");
			out.println(" <tr>");
			out.println(" <td colspan=\"2\" align=\"left\"><h4>Seleccione el servicio que desea pagar</h4></td>");
			out.println("</tr>");
			out.println(" <tr>");
			out.println(" <td><label>Tipo de servicio: </label></td>");
			out.println(" <td> <select name=\"servicio\">");
			out.println("  <option value=\"-1\">-- Selecione un servicio --</option> ");
			Map <String, String> cc = TerceroDAO.findServicios();
			for(Entry<String,String> entry : cc.entrySet()){
				out.println("  <option value=\""+entry.getKey()+"\">"+entry.getValue()+"</option> ");
			}
			out.println("</td>");
			out.println("</tr>");
			out.println(" <tr>");
			out.println("  <td colspan=\"2\" align=\"right\"><button type=\"button\" onclick=\"javascript:history.back(-1)\" class=\"button\">Anterior</button></td>");
			out.println("  <td colspan=\"2\"><button type=\"submit\" class=\"button\">Siguiente</button></td>");
			out.println(" </tr>");
			out.println("</table>");
			out.println("</form>");
			out.println("</div>");
		
		}
		out.println(" <div align=\"right\" id=\"footer\" style=\"width: 80%\">");
		out.println("<img src=\"./images/SiafiReportes.bmp\" width=\"100px\" height=\"30px\"/>");
		out.println("</div>");

		out.println("</body>");
		out.println("</html>");

		out.close();
	}

}
